home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
Q-R
/
RANDOM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-05-25
|
2KB
|
64 lines
Program Random;
{ Turbo Pascal Random Number Generator.
Generates a number between 1 and 100. }
{ Note: Random is for integer random numbers. Use the SANE function
RandomX for extended random numbers. }
{ Anything that works in MacPascal should work in LightSpeed
which is basically compiled MacPascal. Turbo is a Lisa Pascal
descendent and uses Lisa style calls. This means that Random returns
a pseudo-random number from -32768 to 32767 based on the QD global
RandSeed which InitGraph sets to 1. If you want a real random number,
initialize RandSeed using the clock. }
uses Memtypes,QuickDraw,OSIntf,ToolIntf;
function Randomize (range : integer): integer;
{ See Chernicoff V1 p 25 }
var
rawResult : longint;
begin { Randomize }
rawResult := Abs(Random);
Randomize := (rawResult * range ) div 32768
end; { Randomize }
var
seconds : longint;
quit : char;
theWindow : WindowPtr;
WindRect : rect;
datahandle : handle;
const
windTop = 40;
windLeft = 50;
windBottom = 320;
windRight = 350;
begin
InitGraf(@thePort); { The Mac mantra makes the spirits friendly. }
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(NIL);
SetRect(WindRect,windLeft,windTop,
windRight,windBottom);
theWindow := NewWindow(NIL,WindRect,'Random Numbers',
True,NoGrowDocProc,WindowPtr(-1),
True,LongInt(datahandle));
SetPort(theWindow);
GetDateTime(seconds);
RandSeed := seconds;
writeLn( 'Type Q to quit' );
repeat
WriteLn( Randomize(100));
read( quit );
until ( (quit = 'Q') or (quit = 'q') );
end. { of program random }